package logic

import (
	"context"
	"errors"
	"goods_srv/models"

	"goods_srv/goods"
	"goods_srv/internal/svc"

	"github.com/zeromicro/go-zero/core/logx"
)

type UpdateOrderLogic struct {
	ctx    context.Context
	svcCtx *svc.ServiceContext
	logx.Logger
}

func NewUpdateOrderLogic(ctx context.Context, svcCtx *svc.ServiceContext) *UpdateOrderLogic {
	return &UpdateOrderLogic{
		ctx:    ctx,
		svcCtx: svcCtx,
		Logger: logx.WithContext(ctx),
	}
}

// 修改订单状态
func (l *UpdateOrderLogic) UpdateOrder(in *goods.UpdateOrderRequest) (*goods.UpdateOrderResponse, error) {
	// todo: add your logic here and delete this line

	var err error

	var o models.Order
	err = o.UpdateOrderStatus(in.OrderSn, int(in.Status))
	if err != nil {
		logx.Error("订单状态修改失败")
		return nil, errors.New("订单状态修改失败")
	}

	return &goods.UpdateOrderResponse{}, nil
}
